package com.perfma.xtest.tool;

import com.google.common.collect.Lists;
import org.apache.commons.lang.StringUtils;

import java.util.Collections;
import java.util.List;

/**
 * @author: junhui.si
 * @date: 2020-12-07 11:06
 **/
public class JsonDemo2 {

    public static void main(String[] args) {
//        String s = "{\"request\":\"GET http://192.168.0.191:31026/order\\nheaders=\\nAccept: application/json, text/plain, */*\\nAccept-Language: zh-CN,zh;q=0.9,en;q=0.8\\nUser-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.162 Safari/537.36\\naccept-encoding: gzip, deflate\\norigin: http://192.168.0.191:31026\\nhost: 192.168.0.191:31026\\nperfma-batch-id: 74796628556382208\\nXspider-Expand: P-Test-Data:true\\n\",\"contextParameter\":\"Session(SCRIPT-49095804664676352,1,1607062845594,Map(gatling.http.ssl.sslContexts -> SslContexts(io.netty.handler.ssl.OpenSslClientContext@210b237a,None), gatling.http.cache.dns -> io.gatling.http.cache.DnsCacheSupport$$anon$1@344c75e4, 4429b8c6-cd94-4b83-8589-eb933e432d9b -> 0),0,OK,List(GroupBlock(List(trace_mock-191),1607062845601,59,OK), TryMaxBlock(4429b8c6-cd94-4b83-8589-eb933e432d9b,io.gatling.core.action.InnerTryMax@61d0c1c5,OK)),io.gatling.core.protocol.ProtocolComponentsRegistry$$Lambda$492/1966480630@54e1fd59)\",\"reportId\":\"74796628556382208\",\"errTitle\":\"\",\"responseTime\":59.0,\"recvBytes\":0.0,\"groupName\":\"request_0\",\"response\":\"status=\\n200 \\nheaders= \\nContent-Type: application/json;charset=UTF-8\\nContent-Length: 17\\nDate: Fri, 04 Dec 2020 06:20:45 GMT\\n\\n\",\"success\":true,\"name\":\"request_0\",\"api\":\"http://192.168.0.191:31026/order\",\"sentBytes\":0.0,\"group\":false}\n" +
//                "{\"request\":\"GET http://192.168.100.124\\nheaders=\\nAccept: application/json, text/plain, */*\\nAccept-Language: zh-CN,zh;q=0.9,en;q=0.8\\nUser-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.162 Safari/537.36\\naccept-encoding: gzip, deflate\\norigin: http://192.168.100.124\\nhost: 192.168.100.124\\nperfma-batch-id: 74796628556382208\\nXspider-Expand: P-Test-Data:true\\n\",\"contextParameter\":\"Session(SCRIPT-49095804664676352,1,1607062845594,Map(gatling.http.ssl.sslContexts -> SslContexts(io.netty.handler.ssl.OpenSslClientContext@210b237a,None), gatling.http.cache.dns -> io.gatling.http.cache.DnsCacheSupport$$anon$1@344c75e4, 4429b8c6-cd94-4b83-8589-eb933e432d9b -> 0, gatling.http.referer -> http://192.168.100.124),157,OK,List(GroupBlock(List(压124),1607062845871,95,OK), TryMaxBlock(4429b8c6-cd94-4b83-8589-eb933e432d9b,io.gatling.core.action.InnerTryMax@61d0c1c5,OK)),io.gatling.core.protocol.ProtocolComponentsRegistry$$Lambda$492/1966480630@54e1fd59)\",\"reportId\":\"74796628556382208\",\"errTitle\":\"\",\"responseTime\":95.0,\"recvBytes\":0.0,\"groupName\":\"2\",\"response\":\"status=\\n200 OK\\nheaders= \\nServer: nginx\\nDate: Fri, 04 Dec 2020 06:20:45 GMT\\nContent-Type: text/html; charset=UTF-8\\nTransfer-Encoding: chunked\\nConnection: keep-alive\\nVary: Accept-Encoding\\ncontent-encoding: gzip\\n\\n\",\"success\":true,\"name\":\"2\",\"api\":\"http://192.168.100.124\",\"sentBytes\":0.0,\"group\":false}\n" +
//                "{\"request\":\"GET http://192.168.100.124\\nheaders=\\nAccept: application/json, text/plain, */*\\nAccept-Language: zh-CN,zh;q=0.9,en;q=0.8\\nUser-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.162 Safari/537.36\\nReferer: http://192.168.100.124\\naccept-encoding: gzip, deflate\\norigin: http://192.168.100.124\\nhost: 192.168.100.124\\nperfma-batch-id: 74796628556382208\\nXspider-Expand: P-Test-Data:true\\n\",\"contextParameter\":\"Session(SCRIPT-49095804664676352,1,1607062845594,Map(gatling.http.ssl.sslContexts -> SslContexts(io.netty.handler.ssl.OpenSslClientContext@210b237a,None), gatling.http.cache.dns -> io.gatling.http.cache.DnsCacheSupport$$anon$1@344c75e4, 4429b8c6-cd94-4b83-8589-eb933e432d9b -> 0, gatling.http.referer -> http://192.168.100.124),161,OK,List(GroupBlock(List(压124-1),1607062845971,31,OK), TryMaxBlock(4429b8c6-cd94-4b83-8589-eb933e432d9b,io.gatling.core.action.InnerTryMax@61d0c1c5,OK)),io.gatling.core.protocol.ProtocolComponentsRegistry$$Lambda$492/1966480630@54e1fd59)\",\"reportId\":\"74796628556382208\",\"errTitle\":\"\",\"responseTime\":31.0,\"recvBytes\":0.0,\"groupName\":\"3\",\"response\":\"status=\\n200 OK\\nheaders= \\nServer: nginx\\nDate: Fri, 04 Dec 2020 06:20:45 GMT\\nContent-Type: text/html; charset=UTF-8\\nTransfer-Encoding: chunked\\nConnection: keep-alive\\nVary: Accept-Encoding\\ncontent-encoding: gzip\\n\\n\",\"success\":true,\"name\":\"3\",\"api\":\"http://192.168.100.124\",\"sentBytes\":0.0,\"group\":false}";
//
//        Iterable<String> it = Splitter.on("\n").omitEmptyStrings().split(s);
//       it.forEach(t->{
//           System.out.println(t);
//           System.out.println("_____________");
//       });
//        try {
//            int i =3/0;
//        }finally {
//            System.out.println("finally");
//        }

//        GraphicsEnvironment g = GraphicsEnvironment.getLocalGraphicsEnvironment();
//        Font[] fonts = g.getAllFonts();
//        for (Font font : fonts) {
//            System.out.println(font);
//        }
//        String str = "{\"s\":0.0}";
//        JSONObject jsonObject = JSON.parseObject(str);
//        String s = jsonObject.getString("s");
//        System.out.println(JSONValidator.from(s).getType());

//        AgentVersionSyncVO agentVersionSyncVO1 = new AgentVersionSyncVO(AgentVersionSyncVO.VersionSyncState.NOT_SYNC);
//        List<AgentVersionSyncVO> list = Lists.newArrayList(
//                new AgentVersionSyncVO(AgentVersionSyncVO.VersionSyncState.NOT_SYNC),
//                new AgentVersionSyncVO(AgentVersionSyncVO.VersionSyncState.SYNC),
//                new AgentVersionSyncVO(AgentVersionSyncVO.VersionSyncState.SYNC),
//                new AgentVersionSyncVO(AgentVersionSyncVO.VersionSyncState.NOT_SYNC)
//        );
//
//        Collections.sort(list);
//        list.forEach(System.out::println);

        String message = "[时间戳][规则类型][1234][类型][类型信息][底层的错误报错]";
        // 1、提取其中的错误码，匹配对应的错误信息返回
        int startIndex = StringUtils.ordinalIndexOf(message, "[", 3);
        int endIndex = StringUtils.ordinalIndexOf(message, "]", 3);
        String codeStr = message.substring(startIndex+1, endIndex);
        System.out.println(codeStr);

    }
}
